Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't throw InexactError for comparisons between FDs of different types and/or Integers #88

Merged
merged 13 commits into from
Dec 19, 2023

Conversation

NHDaly
Copy link
Member

@NHDaly NHDaly commented Dec 19, 2023

Fixes #82.

Before:

FD{Int8, 0}(2) != FD{Int8, 2}(1)  # Throws because FD{Int8,2}(2) doesn't fit
2 != FD{Int8, 2}(1)  # Throws because FD{Int8,2}(2) doesn't fit
2 >= FD{Int8, 2}(1)  # Throws because FD{Int8,2}(2) doesn't fit

After, these all return true. :)

The idea in this PR is to check whether the values would fit in eachother's types, and if not, that's your answer, rather than throwing an InexactError if they fail to promote.

@NHDaly NHDaly added the bug label Dec 19, 2023
@NHDaly NHDaly marked this pull request as ready for review December 19, 2023 17:47
@NHDaly
Copy link
Member Author

NHDaly commented Dec 19, 2023

Note that this PR doesn't address InexactError caused by promotion during arithmetic, e.g.:

julia> FixedDecimal{Int8,2}(1) + 2  # Same here: 2 is promoted to FD{Int8,2}(2)
ERROR: InexactError: convert(FixedDecimal{Int8, 2}, 2)

I think that's okay for now. If we fixed it, this would either throw an OverflowError anyway if you used checked arithmetic, or it would wrap, using the new semantics. We should probably add support for this, but at least at RAI we're using checked arithmetic for everything so this is going to throw either way and so it seems less urgent to fix it to me.

@NHDaly
Copy link
Member Author

NHDaly commented Dec 19, 2023

Thanks for the quick review! Ready for another round 😊

Copy link

@mcmcgrath13 mcmcgrath13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ thank you!! Can you just make sure we have full test coverage before merging?

@NHDaly
Copy link
Member Author

NHDaly commented Dec 19, 2023

Thanks Mary. 100% diff coverage now. (That's a really helpful tool.)

Here I go! :) I'm gonna also mark this as a patch version bump, since it's a strict improvement.

@NHDaly NHDaly merged commit 507185c into master Dec 19, 2023
14 checks passed
@NHDaly NHDaly deleted the nhd-equality-no-inexacts branch December 19, 2023 22:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

== should not leak promotion failure
2 participants